package org.dkd.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.springframework.kafka.support.ProducerListener;
import org.springframework.stereotype.Component;

/**
 * @className: KafkaProducerListener
 * @Auther: charlie
 * @Date: 2023/3/3 17:37
 * @Description:
 */
@Component
@Slf4j
public class KafkaProducerListener implements ProducerListener<String, String> {
    @Override
    public void onSuccess(ProducerRecord<String, String> producerRecord, RecordMetadata recordMetadata) {
        log.info("推送成功，推送数据：" + producerRecord.value());

    }

    @Override
    public void onError(ProducerRecord<String, String> producerRecord, RecordMetadata recordMetadata, Exception exception) {
        exception.printStackTrace();
        log.error("推送失败，推送数据：" + producerRecord.value() + "，失败原因：" + exception.getMessage());
    }
}
